function SDX_Rows(_RootObject)
{
 this.RootObject = _RootObject ;
 this.GetEvalObjectString = GetEvalObjectString ;
 this.Row = SDX_Row;
 this.InsertRow=InsertRow;
 this.GetRow = GetRow ;
 this.Rows = new Array() ;
 this.SelectedRows = new Array() ;
 this.ClearSelectedRows = ClearSelectedRows ;
 this.DeleteSelectedRows = DeleteSelectedRows ;
 this.EditedCell = null;
 this.SelectedCell = null;
 this.EditedRowWithEditTemplate = null
 this.RemoveAllRows = RemoveAllRows ;
 this.IsEditTemplateValid = true;
 this.ShowEditTemplate = ShowEditTemplate;
 this.HideEditTemplate = HideEditTemplate;
 this.BeforeEditTemplate = BeforeEditTemplate ;
 this.BeforeEditTemplateOnStart = BeforeEditTemplateOnStart ;
 this.BeforeEditTemplateOnEnd = BeforeEditTemplateOnEnd ;
 this.AfterEditTemplate = AfterEditTemplate ;
 this.AfterEditTemplateOnStart = AfterEditTemplateOnStart ;
 this.AfterEditTemplateOnEnd = AfterEditTemplateOnEnd
 this.ApplyChanges = ApplyChanges;
 this.CancelChanges = CancelChanges;
 this.GetEditTemplateConrols = GetEditTemplateConrols;
 this.SetEditTemplateConrols = SetEditTemplateConrols;
 this.SetCellValues = SetCellValues;
 this.Initialize = Initialize ;
 this.HTMLOutPuts = HTMLOutPuts;
 function HideEditTemplate()
 {
     document.getElementById(this.RootObject.EditTemplateHTMLID).style.visibility = 'hidden';
 }
 function ShowEditTemplate(_RowView)
 {
    this.EditedRowWithEditTemplate = _RowView;
    for(var i=0;i<_RowView.Cells.Cells.length;i++)
    {
     this.BeforeEditTemplate(_RowView.Cells.Cells[i]);
    }
    document.getElementById(this.RootObject.EditTemplateHTMLID).style.visibility = 'visible';
    document.getElementById(this.RootObject.EditTemplateHTMLID).style.top = event.clientY + 10 
    document.getElementById(this.RootObject.EditTemplateHTMLID).style.left = event.clientX + 10
    for(var i=0;i<_RowView.Cells.Cells.length;i++)
    {
     this.BeforeEditTemplate(_RowView.Cells.Cells[i]);
    }
 }
 function ApplyChanges()
 {
        for(var i=0;i<this.EditedRowWithEditTemplate.Cells.Cells.length;i++)
        {
         this.AfterEditTemplate(this.EditedRowWithEditTemplate.Cells.Cells[i]);
        }
        this.HideEditTemplate();
 }
 function CancelChanges()
 {
    this.HideEditTemplate();
 }
 function GetEditTemplateConrols(control, columnName, foundControls)
 {
    var newFoundControls = new Array();
    if(foundControls == null)
        foundControls = new Array();
    for(var i=0;i<foundControls.length;i++)
    {
        newFoundControls[newFoundControls.length] = foundControls[i]
    }
        
    for(var i=0;i<control.childNodes.length;i++)
    {
        if(control.childNodes[i].name == ("#" + columnName))
            newFoundControls[newFoundControls.length] = control.childNodes[i];
        tempFoundControls = this.GetEditTemplateConrols(control.childNodes[i], columnName, foundControls);
        for(var ii=0;ii<tempFoundControls.length;ii++)
        {
            newFoundControls[newFoundControls.length] = tempFoundControls[ii];
        }
    }
    return newFoundControls;
 }
 function SetEditTemplateConrols(control, value)
 {
    if(control.type == 'text')
    {
        control.value = value;
    }
    else if(control.type == 'hidden')
    {
        control.value = value;
    }
    else if(control.type == 'checkbox')
    {
        control.checked = value
    }
    else if(control.type == 'radio')
    {
        if(control.value == value)
            control.checked = true
    }
    else if(control.type == 'select')
    {
        for(var i=0;i<control.options.length;i++)
        {
            if(control.options[i].value == value)
                control.options[i].selected = true
        }
    }
 }
 function SetCellValues(control, cell)
 {
    if(control.type == 'text')
    {
        cell.SetValue(control.value);
    }
    else if(control.type == 'hidden')
    {
        cell.SetValue(control.value);
    }
    else if(control.type == 'checkbox')
    {
        cell.SetValue(control.checked);
    }
    else if(control.type == 'radio')
    {
        if(control.checked == true)
            cell.SetValue(control.value)
    }
    else if(control.type == 'select')
    {
        cell.SetValue(control.options[control.options.selectedIndex].value)
    }
 }
 function BeforeEditTemplate(cell)
 {
    controls = this.GetEditTemplateConrols(document.getElementById(this.RootObject.EditTemplateHTMLID), cell.Column.ColumnName, null);
    for(var i=0;i<controls.length;i++)
    {
        this.BeforeEditTemplateOnStart(cell)
    }

    for(var i=0;i<controls.length;i++)
    {
        this.SetEditTemplateConrols(controls[i],cell.Value)
    }
    for(var i=0;i<controls.length;i++)
    {
        this.BeforeEditTemplateOnEnd(cell)
    }
 }
 function AfterEditTemplate(cell)
 {
    controls = this.GetEditTemplateConrols(document.getElementById(this.RootObject.EditTemplateHTMLID), cell.Column.ColumnName, null);
    
    for(var i=0;i<controls.length;i++)
    {
        if(this.AfterEditTemplateOnStart(cell) == false)
            return;
    }
    for(var i=0;i<controls.length;i++)
    {
        this.SetCellValues(controls[i],cell)
        cell.RePaint();
    }
    for(var i=0;i<controls.length;i++)
    {
        this.AfterEditTemplateOnEnd(cell)
    }

 }
 function BeforeEditTemplateOnStart(cell)
 {
 }
 function BeforeEditTemplateOnEnd(cell){}
 function AfterEditTemplateOnStart(cell)
 {
    return true;
 }
 function AfterEditTemplateOnEnd(cell)
 {
    
 }
 function GetEvalObjectString()
 {
  return this.ParentObject.GetEvalObjectString() + ".Rows" ;
 }
 function InsertRow(_DataKeyID, _RootObject)
 {
  this.Rows[this.Rows.length] = new this.Row(this.Rows.length, _DataKeyID, this.RootObject) ;
  return this.Rows[this.Rows.length - 1] ;
 }
 function GetRow(_DataKeyID, _RowIndex)
 {
    return new this.Row(_RowIndex, this.RootObject.GeneralFunctions.CloneArray(this.RootObject.Datas.GetDataByKeyID("Current",_DataKeyID)), this.RootObject) ;
 }
 function RemoveAllRows()
 {
  this.Rows = new Array() ;
 }
 function ClearSelectedRows()
 {
  for(var nX=this.SelectedRows.length-1;nX>-1;nX--)
  {
   this.SelectedRows[nX].Selected = false ;
   if(document.getElementById(this.SelectedRows[nX].HTMLID))
   {
      this.SelectedRows[nX].ChangeCellsClass(null) ;
      this.SelectedRows[nX].ChangeSelectionStatus(0) ;
   }

   this.SelectedRows.splice(nX,1);
  }
 }
  function DeleteSelectedRows()
  {
   var tables = new Array() ;

   for(var nX=this.SelectedRows.length-1;nX>-1;nX--)
   {
    this.SelectedRows[nX].Delete()
   }
   this.ClearSelectedRows();
  }
  function HTMLOutPuts(_Childs)
  {
   var sRows=this.RootObject.Fields.Header;
   for(var nX in _Childs)
   {
    sRows += _Childs[nX].HTMLOutPut();
   }
   return sRows;
  }
  function Initialize()
  {
   this.RemoveAllRows() ;
   for( var nX in this.RootObject.Datas.CurrentDatas)
   {
    if(this.RootObject.Datas.CurrentDatas[nX] != null)
        this.InsertRow(this.RootObject.Datas.CurrentDatas[nX].KeyID, this.RootObject);
   }
  }
 }
